import unittest

from pom.basedriver import BaseDriver
from pom.user.mainpage import MainPage
from pom.user.trogglepage import TrogglePage
from pom.topics.createtopic import CreateTopic
from pom.topics.topicdetaipage import TopicDetailPage
from testcases.basecase import BaseTestCase
from business.useraction import UserAction

class TestTopic(BaseTestCase):

    @classmethod
    def setUpClass(cls) -> None:
        """
        在所有用例执行之前用户登录
        :param cls:
        :return:
        """
        useraction = UserAction()
        useraction.user_login()

    def tearDown(self) -> None:
        # 调用父类中的Teardown方法
        super().tearDown()
        # 每个用例执行完成之后 返回到首页
        BaseDriver.back_to_main_page()


    def test_reply_topic(self):
        """
        测试用例回复话题
        :return:
        """

    def test_new_topic(self):
        """测试用户发帖"""
        main =  MainPage()
        main.click_create_topic()

        ct = CreateTopic()
        ct.new_topic(tab='分享', title='helloworld', content='hhhhhhhhhhhh')

        # 添加断言
        res_text = ct.get_toast_text()
        self.assertEqual(res_text,'发布成功')

    def test_topic_score(self):
        """
        测试用例： 发帖成功能够增加5积分
        :return:
        """
        main = MainPage()
        # 打开抽屉页
        main.open_troggle_page()
        # 获取当前的积分
        tp = TrogglePage()
        score1:str = tp.get_score()
        print(score1)
        tp.close_troggle_page()
        main.click_create_topic()

        ct = CreateTopic()
        ct.new_topic(tab='分享', title='helloworld', content='hhhhhhhhhhhh')

        # 返回到主页面
        tdp = TopicDetailPage()
        tdp.back_to_main_page()
        main.open_troggle_page()
        # 再次获取用户积分
        score2 = tp.get_score()
        print(score2)
        # score1 ="积分：25" 把字符串处理之后提取25
        s1 = int(score1.split('：')[-1].strip())
        s2 = int(score2.split('：')[-1].strip())
        # 添加断言
        self.assertTrue(s2 == s1+5, msg=f'{s2} != {s1}+5')




if __name__ == '__main__':
    unittest.main(verbosity=2)
